package com.dower.clothing.controller;

import java.util.List;

import com.dower.common.annotation.Log;
import com.dower.common.core.controller.BaseController;
import com.dower.common.core.domain.AjaxResult;
import com.dower.common.core.page.TableDataInfo;
import com.dower.common.enums.BusinessType;
import com.dower.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dower.clothing.domain.ClFnModel;
import com.dower.clothing.service.IClFnModelService;


/**
 * 款式字典Controller
 * 
 * @author dower
 * @date 2020-08-26
 */
@Controller
@RequestMapping("/clothing/model")
public class ClFnModelController extends BaseController
{
    private String prefix = "clothing/model";

    @Autowired
    private IClFnModelService clFnModelService;

    @RequiresPermissions("clothing:model:view")
    @GetMapping()
    public String model()
    {
        return prefix + "/model";
    }

    /**
     * 查询款式字典列表
     */
    @RequiresPermissions("clothing:model:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClFnModel clFnModel)
    {
        startPage();
        List<ClFnModel> list = clFnModelService.selectClFnModelList(clFnModel);
        return getDataTable(list);
    }

    /**
     * 导出款式字典列表
     */
    @RequiresPermissions("clothing:model:export")
    @Log(title = "款式字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClFnModel clFnModel)
    {
        List<ClFnModel> list = clFnModelService.selectClFnModelList(clFnModel);
        ExcelUtil<ClFnModel> util = new ExcelUtil<ClFnModel>(ClFnModel.class);
        return util.exportExcel(list, "model");
    }

    /**
     * 新增款式字典
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存款式字典
     */
    @RequiresPermissions("clothing:model:add")
    @Log(title = "款式字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClFnModel clFnModel)
    {
        return toAjax(clFnModelService.insertClFnModel(clFnModel));
    }

    /**
     * 修改款式字典
     */
    @GetMapping("/edit/{numId}")
    public String edit(@PathVariable("numId") Long numId, ModelMap mmap)
    {
        ClFnModel clFnModel = clFnModelService.selectClFnModelById(numId);
        mmap.put("clFnModel", clFnModel);
        return prefix + "/edit";
    }

    /**
     * 修改保存款式字典
     */
    @RequiresPermissions("clothing:model:edit")
    @Log(title = "款式字典", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClFnModel clFnModel)
    {
        return toAjax(clFnModelService.updateClFnModel(clFnModel));
    }

    /**
     * 删除款式字典
     */
    @RequiresPermissions("clothing:model:remove")
    @Log(title = "款式字典", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clFnModelService.deleteClFnModelByIds(ids));
    }
}
